package com.qf.controller;

import com.qf.pojo.repVo.BaseResp;
import com.qf.pojo.reqVo.UserReqVo;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @Value("${qf.username}")
    private String name;

    /**
     * 验证邮箱是否被占用
     * @return
     */
    @RequestMapping("/validataEmail")
    public BaseResp validataEmail(@RequestParam("email")String email){
    return userService.validataEmail(email);
    }

    /**
     * 验证登录名是否被占用
     * @param userReqVo
     * @return
     */
    @RequestMapping("/validataloginName")
    public BaseResp validataloginName(@RequestBody UserReqVo userReqVo){
        return userService.validataloginName(userReqVo);
    }
    /**
     * 发送邮件
     */

    @RequestMapping("/getCode")
    public BaseResp getCode(@RequestParam("email")String email){
        return userService.getCode(email);
    }

    /**
     * 注册接口
     * @param userReqVo
     * @return
     */
    @RequestMapping("/registry")
    public BaseResp registry(@RequestBody UserReqVo userReqVo){
        return userService.registry(userReqVo);
    }
    /**
     * 登录接口
     * @param userReqVo
     * @return
     */
    @RequestMapping("/login")
    public BaseResp login(@RequestBody UserReqVo userReqVo){
        return userService.login(userReqVo);
    }

    /**
     * 通过token获取到用户
     */
    @RequestMapping("/findUserByToken")
    public BaseResp findUserByToken(HttpServletRequest request){
      return userService.findUserByToken(request);
    }

    @RequestMapping("/name")
    private String name(){
        return name;
    }
}
